.class public Lcom/glympse/platform/common/JobQueue;
.super Ljava/lang/Object;
.source "JobQueue.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/glympse/platform/common/JobQueue$CompleteJobOnMainThread;,
        Lcom/glympse/platform/common/JobQueue$Job;,
        Lcom/glympse/platform/common/JobQueue$JobQueueThread;
    }
.end annotation


# static fields
.field public static MAX_PRIORITY:I

.field public static MIN_PRIORITY:I

.field public static NORM_PRIORITY:I


# instance fields
.field protected m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

.field protected volatile m_fExitThreads:Z

.field protected m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

.field protected m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

.field protected m_nPriority:I

.field protected m_oSemaphore:Lcom/glympse/platform/common/SignaledObject;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 22
    const/16 v0, 0xa

    sput v0, Lcom/glympse/platform/common/JobQueue;->MAX_PRIORITY:I

    .line 23
    const/4 v0, 0x1

    sput v0, Lcom/glympse/platform/common/JobQueue;->MIN_PRIORITY:I

    .line 24
    const/4 v0, 0x5

    sput v0, Lcom/glympse/platform/common/JobQueue;->NORM_PRIORITY:I

    .line 20
    return-void
.end method

.method public constructor <init>()V
    .locals 1

    .prologue
    .line 20
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 26
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/glympse/platform/common/JobQueue;->m_fExitThreads:Z

    .line 27
    new-instance v0, Lcom/glympse/platform/common/SignaledObject;

    invoke-direct {v0}, Lcom/glympse/platform/common/SignaledObject;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_oSemaphore:Lcom/glympse/platform/common/SignaledObject;

    .line 28
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    .line 29
    new-instance v0, Lcom/glympse/platform/GVector$Jobs;

    invoke-direct {v0}, Lcom/glympse/platform/GVector$Jobs;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    .line 30
    new-instance v0, Lcom/glympse/platform/GVector$Jobs;

    invoke-direct {v0}, Lcom/glympse/platform/GVector$Jobs;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

    .line 31
    sget v0, Lcom/glympse/platform/common/JobQueue;->NORM_PRIORITY:I

    iput v0, p0, Lcom/glympse/platform/common/JobQueue;->m_nPriority:I

    .line 20
    return-void
.end method


# virtual methods
.method public AddJob(Lcom/glympse/platform/common/JobQueue$Job;)V
    .locals 2
    .parameter "oJob"

    .prologue
    .line 140
    iput-object p0, p1, Lcom/glympse/platform/common/JobQueue$Job;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;

    .line 141
    iget-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    monitor-enter v0

    .line 143
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v1, p1}, Lcom/glympse/platform/GVector$Jobs;->addElement(Ljava/lang/Object;)V

    .line 141
    monitor-exit v0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 145
    iget-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_oSemaphore:Lcom/glympse/platform/common/SignaledObject;

    invoke-virtual {v0}, Lcom/glympse/platform/common/SignaledObject;->AddSignal()V

    .line 146
    return-void

    .line 141
    :catchall_0
    move-exception v1

    :try_start_1
    monitor-exit v0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v1
.end method

.method public RemoveAll()V
    .locals 4

    .prologue
    .line 172
    iget-object v2, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    monitor-enter v2

    .line 175
    :try_start_0
    iget-object v3, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v3}, Lcom/glympse/platform/GVector$Jobs;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iter:Ljava/util/Enumeration;
    :goto_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v3

    if-nez v3, :cond_0

    .line 182
    iget-object v3, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v3}, Lcom/glympse/platform/GVector$Jobs;->removeAllElements()V

    .line 185
    iget-object v3, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v3}, Lcom/glympse/platform/GVector$Jobs;->elements()Ljava/util/Enumeration;

    move-result-object v0

    :goto_1
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v3

    if-nez v3, :cond_1

    .line 192
    iget-object v3, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v3}, Lcom/glympse/platform/GVector$Jobs;->removeAllElements()V

    .line 172
    monitor-exit v2

    .line 194
    return-void

    .line 177
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/glympse/platform/common/JobQueue$Job;

    .line 178
    .local v1, oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    const/4 v3, 0x0

    iput-object v3, v1, Lcom/glympse/platform/common/JobQueue$Job;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;

    goto :goto_0

    .line 172
    .end local v0           #iter:Ljava/util/Enumeration;
    .end local v1           #oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    :catchall_0
    move-exception v3

    monitor-exit v2
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v3

    .line 187
    .restart local v0       #iter:Ljava/util/Enumeration;
    :cond_1
    :try_start_1
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/glympse/platform/common/JobQueue$Job;

    .line 188
    .restart local v1       #oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    const/4 v3, 0x0

    iput-object v3, v1, Lcom/glympse/platform/common/JobQueue$Job;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_1
.end method

.method public RemoveJob(Lcom/glympse/platform/common/JobQueue$Job;)Z
    .locals 3
    .parameter "oJob"

    .prologue
    const/4 v2, 0x1

    .line 151
    iget-object v0, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    monitor-enter v0

    .line 153
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v1, p1}, Lcom/glympse/platform/GVector$Jobs;->removeElement(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 155
    const/4 v1, 0x0

    iput-object v1, p1, Lcom/glympse/platform/common/JobQueue$Job;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;

    .line 156
    monitor-exit v0

    move v0, v2

    .line 166
    :goto_0
    return v0

    .line 159
    :cond_0
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v1, p1}, Lcom/glympse/platform/GVector$Jobs;->removeElement(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 161
    const/4 v1, 0x0

    iput-object v1, p1, Lcom/glympse/platform/common/JobQueue$Job;->m_oJobQueue:Lcom/glympse/platform/common/JobQueue;

    .line 162
    monitor-exit v0

    move v0, v2

    goto :goto_0

    .line 151
    :cond_1
    monitor-exit v0

    .line 166
    const/4 v0, 0x0

    goto :goto_0

    .line 151
    :catchall_0
    move-exception v1

    monitor-exit v0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v1
.end method

.method public SetPriority(I)V
    .locals 2
    .parameter "nPriority"

    .prologue
    .line 127
    iput p1, p0, Lcom/glympse/platform/common/JobQueue;->m_nPriority:I

    .line 128
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    if-eqz v1, :cond_0

    .line 130
    const/4 v0, 0x0

    .local v0, nThread:I
    :goto_0
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    array-length v1, v1

    if-lt v0, v1, :cond_1

    .line 135
    .end local v0           #nThread:I
    :cond_0
    return-void

    .line 132
    .restart local v0       #nThread:I
    :cond_1
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v1, v1, v0

    invoke-virtual {v1, p1}, Lcom/glympse/platform/common/JobQueue$JobQueueThread;->setPriority(I)V

    .line 130
    add-int/lit8 v0, v0, 0x1

    goto :goto_0
.end method

.method public Start(I)Z
    .locals 3
    .parameter "nThreads"

    .prologue
    const/4 v2, 0x0

    .line 37
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    if-nez v1, :cond_1

    .line 39
    const-string v1, "JobQueue::Start"

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 41
    iput-boolean v2, p0, Lcom/glympse/platform/common/JobQueue;->m_fExitThreads:Z

    .line 44
    new-array v1, p1, [Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    iput-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    .line 45
    const/4 v0, 0x0

    .local v0, nThread:I
    :goto_0
    if-lt v0, p1, :cond_0

    .line 51
    const/4 v1, 0x1

    .line 54
    .end local v0           #nThread:I
    :goto_1
    return v1

    .line 47
    .restart local v0       #nThread:I
    :cond_0
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    new-instance v2, Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    invoke-direct {v2, p0}, Lcom/glympse/platform/common/JobQueue$JobQueueThread;-><init>(Lcom/glympse/platform/common/JobQueue;)V

    aput-object v2, v1, v0

    .line 48
    iget-object v1, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v1, v1, v0

    iget v2, p0, Lcom/glympse/platform/common/JobQueue;->m_nPriority:I

    invoke-virtual {v1, v2}, Lcom/glympse/platform/common/JobQueue$JobQueueThread;->setPriority(I)V

    .line 45
    add-int/lit8 v0, v0, 0x1

    goto :goto_0

    .end local v0           #nThread:I
    :cond_1
    move v1, v2

    .line 54
    goto :goto_1
.end method

.method public Stop(Z)V
    .locals 6
    .parameter "fWait"

    .prologue
    .line 60
    const-string v4, "JobQueue::Stop"

    invoke-static {v4}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 63
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    monitor-enter v4

    .line 66
    :try_start_0
    iget-object v5, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsPending:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v5}, Lcom/glympse/platform/GVector$Jobs;->elements()Ljava/util/Enumeration;

    move-result-object v1

    .local v1, iter:Ljava/util/Enumeration;
    :goto_0
    invoke-interface {v1}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v5

    if-nez v5, :cond_2

    .line 73
    iget-object v5, p0, Lcom/glympse/platform/common/JobQueue;->m_listJobsRunning:Lcom/glympse/platform/GVector$Jobs;

    invoke-virtual {v5}, Lcom/glympse/platform/GVector$Jobs;->elements()Ljava/util/Enumeration;

    move-result-object v1

    :goto_1
    invoke-interface {v1}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v5

    if-nez v5, :cond_3

    .line 63
    monitor-exit v4
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 81
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    if-eqz v4, :cond_1

    .line 84
    const/4 v4, 0x1

    iput-boolean v4, p0, Lcom/glympse/platform/common/JobQueue;->m_fExitThreads:Z

    .line 87
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_oSemaphore:Lcom/glympse/platform/common/SignaledObject;

    iget-object v5, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    array-length v5, v5

    invoke-virtual {v4, v5}, Lcom/glympse/platform/common/SignaledObject;->AddSignals(I)V

    .line 90
    const/4 v2, 0x0

    .local v2, nThread:I
    :goto_2
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    array-length v4, v4

    if-lt v2, v4, :cond_4

    .line 106
    if-eqz p1, :cond_0

    .line 109
    const/4 v2, 0x0

    :goto_3
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    array-length v4, v4

    if-lt v2, v4, :cond_6

    .line 118
    :cond_0
    const/4 v4, 0x0

    iput-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    .line 121
    .end local v2           #nThread:I
    :cond_1
    invoke-virtual {p0}, Lcom/glympse/platform/common/JobQueue;->RemoveAll()V

    .line 122
    return-void

    .line 68
    :cond_2
    :try_start_1
    invoke-interface {v1}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lcom/glympse/platform/common/JobQueue$Job;

    .line 69
    .local v3, oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    invoke-virtual {v3}, Lcom/glympse/platform/common/JobQueue$Job;->Abort()V

    goto :goto_0

    .line 63
    .end local v1           #iter:Ljava/util/Enumeration;
    .end local v3           #oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    :catchall_0
    move-exception v5

    monitor-exit v4
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v5

    .line 75
    .restart local v1       #iter:Ljava/util/Enumeration;
    :cond_3
    :try_start_2
    invoke-interface {v1}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lcom/glympse/platform/common/JobQueue$Job;

    .line 76
    .restart local v3       #oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    invoke-virtual {v3}, Lcom/glympse/platform/common/JobQueue$Job;->Abort()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    goto :goto_1

    .line 92
    .end local v3           #oJobCur:Lcom/glympse/platform/common/JobQueue$Job;
    .restart local v2       #nThread:I
    :cond_4
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v4, v4, v2

    if-eqz v4, :cond_5

    .line 96
    :try_start_3
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v4, v4, v2

    invoke-virtual {v4}, Lcom/glympse/platform/common/JobQueue$JobQueueThread;->interrupt()V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_0

    .line 90
    :cond_5
    :goto_4
    add-int/lit8 v2, v2, 0x1

    goto :goto_2

    .line 98
    :catch_0
    move-exception v4

    move-object v0, v4

    .line 101
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_4

    .line 111
    .end local v0           #e:Ljava/lang/Exception;
    :cond_6
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v4, v4, v2

    if-eqz v4, :cond_7

    .line 113
    iget-object v4, p0, Lcom/glympse/platform/common/JobQueue;->m_aoThreads:[Lcom/glympse/platform/common/JobQueue$JobQueueThread;

    aget-object v4, v4, v2

    iget-object v4, v4, Lcom/glympse/platform/common/JobQueue$JobQueueThread;->m_oThreadExited:Lcom/glympse/platform/common/SignaledObject;

    invoke-virtual {v4}, Lcom/glympse/platform/common/SignaledObject;->WaitForSignal()Z

    .line 109
    :cond_7
    add-int/lit8 v2, v2, 0x1

    goto :goto_3
.end method
